
import os 
 
import sys
from PySide6.QtCore import QObject,Property,Signal, Slot,Qt

class WQTheme(QObject):
    # 通知信号
    radiusChanged = Signal(float)
    foregroundChanged = Signal(str)
    titleBackgroundChanged = Signal(str)
    deactiveTitleBackgroundChanged = Signal(str)
    backgroundChanged = Signal(str)
    controlBackgroundChanged = Signal(str)
    accentChanged = Signal(str)
    successChanged = Signal(str)
    primaryChanged = Signal(str)
    warningChanged = Signal(str)
    infoChanged = Signal(str)
    errorChanged = Signal(str)
    textChanged = Signal(str)
    textSecondaryChanged = Signal(str)
    textHintChanged = Signal(str)
    textDisabledChanged = Signal(str)
    dividerChanged = Signal(str)
    osChanged = Signal(bool)
    themeChanged = Signal(bool)
    def __init__(self,colorScheme = Qt.ColorScheme.Dark):
        super().__init__()
        self.colorScheme:Qt.ColorScheme = colorScheme
        self.platform  =  sys.platform ##== 'darwin' # win32 darwin linux
        self._radius = 2
    @Property(bool,notify=themeChanged)
    def theme(self):
        return self.colorScheme == Qt.ColorScheme.Light
    @theme.setter
    def theme(self, value):
        self.colorScheme = Qt.ColorScheme.Dark if  self.theme else Qt.ColorScheme.Light
        self.themeChanged.emit(self.theme)
        self.titleBackgroundChanged.emit(self.titleBackground)
        self.deactiveTitleBackgroundChanged.emit(self.deactiveTitleBackground)
        self.backgroundChanged.emit(self.background)
        self.controlBackgroundChanged.emit(self.controlBackground)
        self.foregroundChanged.emit(self.foreground)
        print(f'colorScheme: {self.colorScheme},titleBackground:{self.titleBackground}')
    @Property(bool,notify=osChanged)
    def macOS(self):
        return self.platform == 'darwin'
    
    @macOS.setter
    def macOS(self, value):
        self.platform = "win32" if  self.platform == 'darwin' else "darwin"
        self.osChanged.emit(self.macOS)
        print(f'platform: {self.platform}')
        # self.themeChanged.emit(self.theme)
        # self.titleBackgroundChanged.emit(self.titleBackground)
        # self.deactiveTitleBackgroundChanged.emit(self.deactiveTitleBackground)
        # self.backgroundChanged.emit(self.background)
        # self.controlBackgroundChanged.emit(self.controlBackground)
        # self.foregroundChanged.emit(self.foreground)
        # print(f'colorScheme: {self.colorScheme},titleBackground:{self.titleBackground}')
    @Property(float, notify=radiusChanged)
    def radius(self):
        return self._radius
    
    #               标题栏背景色   整体背景色   控件背景色   文字前景色
   
    # 暗色模式分别为  #383838      #202020     #666666    #f0f0f0
    # 亮色模式分别为  #f0f0f0      #ffffff     #efefef    #202020

    @Property(str, notify = titleBackgroundChanged)
    def titleBackground(self):
        return '#383838' if self.colorScheme  ==  Qt.ColorScheme.Dark  else  '#f0f0f0'
    
    @Property(str, notify=deactiveTitleBackgroundChanged)
    def deactiveTitleBackground(self):
        return '#454545' if self.colorScheme ==  Qt.ColorScheme.Dark  else  '#e9e9e9'
    
    @Property(str,notify=backgroundChanged)
    def background(self):
        return '#202020' if self.colorScheme ==  Qt.ColorScheme.Dark  else  '#ffffff'
    
    @Property(str, notify=controlBackgroundChanged)
    def controlBackground(self):
        return '#666666' if self.colorScheme ==  Qt.ColorScheme.Dark  else  '#efefef'
    
    @Property(str, notify=foregroundChanged)
    def foreground(self):
        return  '#f0f0f0' if self.colorScheme ==  Qt.ColorScheme.Dark else  '#202020'
    
    @Property(str, notify=accentChanged)
    def accent(self):
        '''主题色
        '''
        return '#3f51b5'
    
    @Property(str, notify=successChanged)
    def success(self):
        '''成功色
        '''
        return '#4CAF50'
    @Property(str, notify=primaryChanged)
    def primary(self):
        '''主色
        '''
        return '#3f51b5'
    @Property(str, notify=warningChanged)
    def warning(self):
        '''警告色
        '''
        return '#FFC107'
    @Property(str, notify=infoChanged)
    def info(self):
        '''信息色
        '''
        return '#2196F3'
    @Property(str, notify=errorChanged)
    def error(self):
        '''错误色
        '''
        return '#FF5722'
    @Property(str, notify=dividerChanged)
    def text(self):
        '''文字颜色
        '''
        return '#333333' if self.colorScheme ==  Qt.ColorScheme.Dark  else '#ffffff'
    @Property(str, notify=textSecondaryChanged)
    def textSecondary(self):
        '''次要文字颜色
        '''
        return '#666666' if self.colorScheme ==  Qt.ColorScheme.Dark  else '#ffffff'
    @Property(str, notify=textHintChanged)
    def textHint(self):
        '''提示文字颜色
        '''
        return '#999999' if self.colorScheme ==  Qt.ColorScheme.Dark  else '#ffffff'
    @Property(str, notify=textDisabledChanged)
    def textDisabled(self):
        '''禁用文字颜色
        '''
        return '#cccccc' if self.colorScheme ==  Qt.ColorScheme.Dark  else '#ffffff'
    @Property(str, notify=dividerChanged)
    def divider(self):
        '''分割线颜色
        '''
        return '#eeeeee' if self.colorScheme ==  Qt.ColorScheme.Dark  else '#ffffff'
   
    